package java复习202408.H_反射;

import org.junit.jupiter.api.Test;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class h1_反射测试 {

    @Test
    public void test() throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchFieldException, NoSuchMethodException, InvocationTargetException {
        Class aClass = Class.forName("java复习202408.H_反射.demo1");

        demo1 o = (demo1) aClass.newInstance();
        o.sayHello();

        Method sayHello = aClass.getMethod("sayHello",null);
        Object invoke = sayHello.invoke(null);


        Field[] fields = aClass.getFields();
        System.out.println(fields.length);
        for (Field field : fields) {
            System.out.println(field.getName());

        }

    }

}
